package com.hackafone.storytail;


import com.hackafone.storytail.R;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.LinearLayout.LayoutParams;


public class BaseActivity extends Activity
{
	private StoryTailApplicationContext mAppContext;
	private LinearLayout baseLayout;

	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);

		mAppContext = (StoryTailApplicationContext) getApplicationContext();
		requestWindowFeature(Window.FEATURE_NO_TITLE);

		super.setContentView(R.layout.base_activity_layout);

		baseLayout = (LinearLayout) findViewById(R.id.root_container);
	}

	@Override
	public void setContentView(int layoutResID)
	{
		View v = getLayoutInflater().inflate(layoutResID, null);
		
		LinearLayout.LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, 1f);
		v.setLayoutParams(lp);
		
		baseLayout.addView(v);
	}
	

	protected StoryTailApplicationContext getCareAppContext()
	{
		return mAppContext;
	}

	protected void addActionBarButton(int btnid, int imageRes, OnClickListener clickListner)
	{
		ImageView imgBtn = (ImageView) findViewById(btnid);
		imgBtn.setImageResource(imageRes);
		imgBtn.setOnClickListener(clickListner);
	}
	
	protected void hideActionBarButton(int btnid)
	{
		ImageView imgBtn = (ImageView) findViewById(btnid);
		if(imgBtn != null)
			imgBtn.setVisibility(View.GONE);
	}

	protected void setEnableActionBarButton(int btnID, boolean enabled)
	{
		ImageView imgBtn = (ImageView) findViewById(btnID);
		if(imgBtn != null)
			imgBtn.setEnabled(enabled);
		
	}
	
	@Override
	public void setTitle(int textRes)
	{
		TextView tv = (TextView) findViewById(android.R.id.title);
		tv.setText(textRes);
	}

	@Override
	public void setTitle(CharSequence title)
	{
		ImageView img = (ImageView) findViewById(R.id.title_img);
		img.setVisibility(View.GONE);
		
		TextView tv = (TextView) findViewById(android.R.id.title);
		tv.setVisibility(View.VISIBLE);
		
		tv.setText(title);
	}
	
	public void setTitleImage(int resId)
	{
		TextView tv = (TextView) findViewById(android.R.id.title);
		tv.setVisibility(View.GONE);
		
		ImageView img = (ImageView) findViewById(R.id.title_img);
		img.setVisibility(View.VISIBLE);
		
		img.setImageResource(resId);
	}
}
